﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Framework.Dependency;
using Interfaces.Criteria;
using Interfaces.Filters;
using Interfaces.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using YQLDataProvider;
using YQLDataProvider.Providers;

namespace DataProviderIntegrationTests.ProvidersTests
{
    [TestClass]
    public class YqlQuoteisDataProviderTests
    {
        [ClassInitialize]
        public static void InitTests(TestContext context)
        {
            var module = new YqlDataProviderModule(DependencyManager.Container);
            module.Initialize();
        }

        [TestMethod]
        public void GetDataTest_IsLazyLoadingTrue_OnlyQuoteisSomeDataReturned()
        {
            YqlIndustryProviderTetsTemplate(given: (criteria, filter) =>
                {
                    criteria.Setup(x => x.IsLazyLoading).Returns(true);
                    criteria.Setup(x => x.IsFullLoading).Returns(false);
                    criteria.Setup(x => x.Identificators).Returns(new object[] { "APPL" });
                    filter.Setup(x => x.Filtrate(It.IsAny<IEnumerable<object>>())).Returns((IEnumerable<object> y) => y);
                },when: (provider,criteria,filter)=> provider.GetData(criteria,filter), then: (result) =>
                    {
                        Assert.IsNotNull(result);
                        foreach (var quote in result)
                            Assert.IsNull(quote.Company);
                    });
        }

        private static void YqlIndustryProviderTetsTemplate(Action<Mock<IKeySupportedCriteria>, Mock<IQuoteisFilter>> given,
                                                   Func<YqlQuoteDataProvider, IKeySupportedCriteria, IQuoteisFilter, IEnumerable<IQuote>> when,
                                                   Action<IEnumerable<IQuote>> then)
        {
            var provider = new YqlQuoteDataProvider();
            var keyCriteria = new Mock<IKeySupportedCriteria>();
            var filter = new Mock<IQuoteisFilter>();
            given(keyCriteria, filter);
            var result = when(provider, keyCriteria.Object, filter.Object);
            then(result);
        }
    }
}
